class Solution
{
public:
    int findLongestChain(vector<vector<int>> &pairs)
    {
        sort(pairs.begin(), pairs.end(), Solution::SecondValComparator);
        int maxLen = 0;
        int lastUpper = pairs[0][0] - 1;
        for (auto &pair : pairs)
        {
            if (pair[0] > lastUpper)
            {
                ++maxLen;
                lastUpper = pair[1];
            }
        }
        return maxLen;
    }

private:
    static bool SecondValComparator(const vector<int> &leftPair, const vector<int> &rightPair)
    {
        return leftPair[1] < rightPair[1];
    }
};